home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.013.OOPTESample / SCN.013.OOPTESample < prev    next >
Encoding:
Text File  |  1990-01-16  |  5.1 KB  |  110 lines  |  [TEXT/MPS ]

  1. Macintosh
  2. Sample Code Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. #13:    OOPTESample
  7.  
  8. Written by:    Keith Rollin
  9.  
  10. Versions:            1.00                        April 1989
  11.                     1.1                         February 1990
  12.  
  13. Components:            BuildOOPTESample            February 1, 1990
  14.                     MOOPTESample.p                February 1, 1990
  15.                     OOPTESample.make            February 1, 1990
  16.                     TECommon.h                    February 1, 1990
  17.                     TESampleGlue.a                February 1, 1990
  18.                     TESample.r                    February 1, 1990
  19.                     UApplication.p                February 1, 1990
  20.                     UApplication.inc1.p            February 1, 1990
  21.                     UDocument.p                    February 1, 1990
  22.                     UDocument.inc1.p            February 1, 1990
  23.                     UTEDocument.p                February 1, 1990
  24.                     UTEDocument.inc1.p            February 1, 1990
  25.                     UTESample.p                    February 1, 1990
  26.                     UTESample.inc1.p            February 1, 1990
  27. _____________________________________________________________________________
  28.  
  29. The build process for OOPTESample is entirely automated.  All you 
  30. need to do is run the BuildOOPTESample script.  BuildOOPTESample 
  31. is a variation on the BuildProgram script that comes standard with 
  32. MPW.  It creates a folder to contain the intermediary object 
  33. files, and then calls Make with the file OOPTESample.make.  
  34. Make’s output is executed with the final application OOPTESample 
  35. as the result.
  36. _____________________________________________________________________________
  37.  
  38. OOPTESample is an example application that demonstrates how to 
  39. initialize the commonly used Toolbox managers, operate 
  40. successfully under MultiFinder, handle desk accessories, and 
  41. create, grow, and zoom windows.  It demonstrates fundamental 
  42. TextEdit toolbox calls and TextEdit automatic scrolling, and it 
  43. shows how to create and maintain scroll bar controls.
  44.  
  45. This version of TESample has been substantially reworked in Object 
  46. Pascal to show how a “typical” object-oriented program could be 
  47. written.  To this end, what was once a single source code file has 
  48. been restructured into a set of classes which demonstrate the 
  49. advantages of object-oriented programming.
  50.  
  51. There are four main classes in this program.  Each one of these 
  52. has an interface (.p) file and an implementation (.inc1.p) file, 
  53. and is compiled into its own separate UNIT.
  54.  
  55. The TApplication class does all of the basic event handling and 
  56. initialization necessary for Macintosh Toolbox applications.  It 
  57. maintains a list of TDocument objects and passes events to the 
  58. correct TDocument class when appropriate.
  59.  
  60. The TDocument class does all of the basic document handling work.  
  61. TDocuments are objects that are associated with a window.  Methods 
  62. are provided to deal with update, activate, mouse-click, key-down, 
  63. and other events.  Some additional classes which implement a 
  64. linked list of TDocument objects are provided.
  65.  
  66. The TApplication and TDocument classes together define a basic 
  67. framework for Macintosh applications, without having any specific 
  68. knowledge about the type of data being displayed by the 
  69. application’s documents. They are a (very) crude implementation of 
  70. the MacApp application model, without the sophisticated view 
  71. hierarchies or any real error handling.
  72.  
  73. The TESample class is a subclass of TApplication.  It overrides 
  74. several TApplication methods, including those for handling menu 
  75. commands and cursor adjustment, and it does some necessary 
  76. initialization.  Note that we only need to override nine methods 
  77. to create a useful application class.
  78.  
  79. The TEDocument class is a subclass of TDocument.  This class 
  80. contains most of the special-purpose code for text editing.  In 
  81. addition to overriding most of the TDocument methods, it defines a 
  82. number of additional methods which are used by the TESample class 
  83. to get information on the document state.
  84.  
  85. This program consists of four segments.  “Main” contains most of 
  86. the code, including the MPW libraries and the main program.  
  87. “Initialize” contains code that is used only once, or rarely, and 
  88. can be unloaded after the event loop is completed.  “%A5Init” is 
  89. automatically created by the Linker to initialize globals for the 
  90. MPW libraries and is unloaded right away.  “%_MethTables” is a 
  91. fake segment used by Object Pascal to maintain object 
  92. relationships.
  93.  
  94. Toolbox routines do not change the current port.  In spite of 
  95. this, in this program we use a strategy of calling _SetPort 
  96. whenever we want to draw or make calls which depend on the current 
  97. port.  This precaution makes us less vulnerable to bugs in other 
  98. software which might alter the current port (such as the bug 
  99. (feature?) in many desk accessories which changes the port when 
  100. there is a call to _OpenDeskAcc).  Hopefully, this also makes the 
  101. routines from this program more self-contained, since they don’t 
  102. depend on the current port setting.
  103.  
  104. This program does not maintain a private scrap.  Whenever a cut, 
  105. copy, or paste occurs, we import or export from the public scrap 
  106. to TextEdit’s scrap right away, using the TEToScrap and 
  107. TEFromScrap routines.  If we did use a private scrap, the import 
  108. or export would be in the activate or deactivate event and suspend 
  109. or resume event routines.
  110.